home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: Floating point calculation order
- Date: 23 Jan 1996 21:46:37 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Jan23144637@qcd.lanl.gov>
- References: <m0tedv8-0002eqC@sice.nsk.su> <3104c6d9.134061184@nntp.ix.netcom.com>
- <DLnE5K.2xH@microunity.com>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: toms@MicroUnity.com's message of Tue, 23 Jan 1996 19:00:56 GMT
-
- --text follows this line--
- In article <DLnE5K.2xH@microunity.com> toms@MicroUnity.com (Tom
- Sanders) writes:
- <snip>
- |> > Having declaration
- |> >
- |> > double x, p, q, r;
- |> >
- |> > my compiler (cc on SCO 3.2) calculated following expression:
- |> >
- |> > x = p * q / r;
- |> >
- |> > as p * (q/r); (I mean, it divided first, than multiplied). That
- |> > resulted in precision loss.
- |> >
- |> > Is this legal behavior?
- |>
- |> Not in ANSI C, but it was legal in K&R. If memory serves, it was not
- |> made illegal until very late in the standardizattion process so if
- |> your compiler was written before the standard was finalized it may not
- |> adhere to this.
- |>
- |> Michael M Rubenstein
-
- I am a firm believer in not allowing a compiler to make these decisions for
- me. It's best to specify with parens the order of evaluation and not leave
- it up to the compiler defaults. I would actually prefer a compiler that
-
- I agree that redundant parens are often useful for clarity, but I take
- issue at calling language semantics as `compiler defaults'. When I
- write in C, I expect everyone reading it to know C, and the compiler
- to compile according to C rules.
-
- I write `a = b + c' instead of `a = (b + c)' regularly, and I would
- refuse to buy a compiler which thought `(a = b) + c' was an alternate
- meaning I might have been thinking of, and warn me about such
- possibilities.
-
- There is absolutely no ambiguity in `p * q / r', and no parentheses
- are necessary.
-
- gave a warning if I did have an equation that could be evaluated in more
- than 1 order (something I have not done in over 20 years).
-
- I am almost certain you write `a + b * c' contrary to your claim. Do
- you mean `a + (b * c)' or `(a + b) * c' when, if, you do it? If you do
- not, you are in a very small minority.
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-